<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button v-waves v-permission="['dataextraction:DataExtractionDetail:add']" class="filter-item" style="margin-left: 10px" type="primary" icon="el-icon-edit" @click="handleCreate">
        {{ $t('table.add') }}
      </el-button>
    </div>

    <el-table ref="table" :key="tableKey" v-loading="listLoading" :data="list" element-loading-text="正在加载，请稍后" border fit highlight-current-row style="width: 100%">
      <el-table-column label="操作" fixed="right" align="center" min-width="230" class-name="small-padding fixed-width">
        <template slot-scope="{ row }">
          <el-button v-permission="['dataextraction:DataExtractionDetail:update']" type="text" size="small" icon="el-icon-edit" @click="handleUpdate(row)">
            {{ $t('table.edit') }}
          </el-button>
          <el-button v-permission="['dataextraction:DataExtractionDetail:delete']" type="text" size="small" icon="el-icon-delete" class="delete-text-btn" @click="handleDelete(row)">
            {{ $t('table.delete') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" :page-sizes="pageArray" @pagination="getList" />

    <data-extraction-detail-form ref="form" @refreshList="getList" />
  </div>
</template>

<script>
import { deleteDataExtractionDetail, fetchDataExtractionDetailList } from '@/api/dataextractiondetail/dataExtractionDetail'
import waves from '@/directive/waves' // waves directive
import permission from '@/directive/permission/permission'
import dataExtractionDetailForm from './dataExtractionDetailForm'
import Pagination from '@/components/Pagination'

export default {
  name: 'DataExtractionDetailList',
  components: { dataExtractionDetailForm, Pagination },
  directives: { waves, permission },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      pageArray: this.$store.getters.pageArray,
      listQuery: {
        page: 1,
        limit: this.$store.getters.defaultPageSize,
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchDataExtractionDetailList(this.listQuery).then((response) => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    handleCreate() {
      this.$refs.form.handleCreate()
    },
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row.id)
    },
    handleDelete(row) {
      this.$confirm('确定删除该数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteDataExtractionDetail(row.id).then((response) => {
          if (response.data.code === 0) {
            this.getList()
            this.$message.success(response.data.msg)
          } else {
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep(::-webkit-scrollbar) {
  display: block !important;
}
</style>
